<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
	  xmlns:th="http://www.thymeleaf.org"
	  xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity3"
	  xmlns:layout="http://www.ultrag.net.nz/thymeleaf/layout">
<head>
<meta charset="UTF-8">
<title>注册</title>
<link th:href="@{/css/bootstrap.min.css}" rel="stylesheet"/>
</head>
<body>
	<div class="container" style="text-align:center;margin-top:50px;">
	   <div class="row col-md-6 col-md-offset-3">
	       <div class="panel panel-default">
			    <div class="panel-heading" th:text="${title}">注册页面</div>
			    <div class="panel-body">
			     	<form id="registerForm"  th:action="@{/register}" th:object="${user}" method="post">
			     		<div class="input-group">
				            <span class="input-group-addon">username</span>
				            <!-- <input 	id="username" type="text" name="username" class="form-control" placeholder="用户名"> -->
				            <input id="username" type="text" th:field="*{username}" class="form-control" placeholder="用户名">
				        </div>
				        <div><span th:if="${#fields.hasErrors('username')}" th:errors="*{username}" style="color:red;"></span></div>
				        <br>
				        <div class="input-group">
				            <span class="input-group-addon">password</span>
				            <!-- <input id="password" type="password" name="password" class="form-control" placeholder="密码"> -->
				            <!-- <input id="password" type="password" th:field="*{password}" class="form-control" placeholder="密码" required>-->
				            <input id="password" type="password" name="password" class="form-control" placeholder="密码" required>
				        </div>
				        <div><span th:if="${#fields.hasErrors('password')}" th:errors="*{password}" style="color:red;"></span></div>
				         <br>
				         <div class="input-group">
				            <span class="input-group-addon">re-password</span>
				            <!-- <input id="repassword" type="password" name="repassword" class="form-control" placeholder="确认密码"> -->
				            <input id="repassword" type="password" th:field="*{repassword}" class="form-control" placeholder="确认密码" required>
				        </div>
				       
				        <br>
						<button type="submit" class="btn btn-primary register-btn">注册</button>
						<button type="reset" class="btn btn-warning">重置</button>
					</form>
			    </div>
			</div>
	   </div>
	</div>
</body>
<script th:src="@{/js/jquery-3.3.1.js}"></script>
<script th:src="@{/js/jquery.validate.min.js}"></script>
<script th:src="@{/js/additional-methods.min.js}"></script>
<script th:src="@{/js/messages_zh.min.js}"></script>
<script th:src="@{/js/jquery.md5.js}"></script>
<script>
	
	$("#registerForm").validate({
  	  rules: {
  		  	password: {
  		      required: true,
  		      minlength: 4,
  		      maxlength: 100,
  		    },
  		    repassword: {
  		      equalTo: "#password"
  		    }
  		  },
	 	errorPlacement: function(error, element) {  
	    	error.appendTo(element.parent());  
	     },
	     submitHandler:function(form){
	    	 debugger;
	    	 var salt = 'springboot'
			 var newPassword = $.md5($("#password").val() + salt);
	    	 $("#password").val(newPassword);
	    	 form.submit();
				
	    	 /*
				$.ajax({
					url: "/register",
				    type: "POST",
				    data:{
				    	username:$("#username").val(),
				    	password: newPassword
				    },
				    success:function(data){
				    	alert('success');
				    },
				    error:function(){
				    }
				});
	    	 */
			 } 
	 });
	
</script>
</html>